package com.cooper.moviedb.bo;

import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.sql.Timestamp;

/**
 * Created with IntelliJ IDEA.
 * User: cooperlee
 * Date: 11/19/12
 * Time: 12:29 PM
 */

@javax.persistence.Table(name = "MEDIA_URI", schema = "", catalog = "media_service_db")
@Entity
public class MediaUriEntity {

    public MediaUriEntity(){

    }

    public MediaUriEntity(MediaEntity mediaEntity, String url, Timestamp joinTime, boolean deleted) {
        this.mediaEntity = mediaEntity;
        this.url = url;
        this.joinTime = joinTime;
        this.deleted = deleted;
    }

    private String id;

    @Id
    @GenericGenerator(name="idGenerator",strategy = "uuid")
    @GeneratedValue(generator = "idGenerator")
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    private MediaEntity mediaEntity;

    @ManyToOne()
    @JoinColumn(name = "MEDIA_ID", referencedColumnName = "id")
    public MediaEntity getMediaEntity() {
        return mediaEntity;
    }

    public void setMediaEntity(MediaEntity mediaEntity) {
        this.mediaEntity = mediaEntity;
    }

    private String url;

    @javax.persistence.Column(name = "URL", nullable = false, insertable = true, updatable = true, length = 200, precision = 0)
    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    private Timestamp joinTime;

    @javax.persistence.Column(name = "JOIN_TIME", nullable = true, insertable = true, updatable = true, length = 19, precision = 0)
    @Basic
    public Timestamp getJoinTime() {
        return joinTime;
    }

    public void setJoinTime(Timestamp joinTime) {
        this.joinTime = joinTime;
    }

    private boolean deleted;

    @javax.persistence.Column(name = "DELETED", nullable = true, insertable = true, updatable = true, length = 0, precision = 0)
    @Basic
    public boolean isDeleted() {
        return deleted;
    }

    public void setDeleted(boolean deleted) {
        this.deleted = deleted;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        MediaUriEntity that = (MediaUriEntity) o;

        if (deleted != that.deleted) return false;
        if (id != null ? !id.equals(that.id) : that.id != null) return false;
        if (joinTime != null ? !joinTime.equals(that.joinTime) : that.joinTime != null) return false;
        if (url != null ? !url.equals(that.url) : that.url != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (url != null ? url.hashCode() : 0);
        result = 31 * result + (joinTime != null ? joinTime.hashCode() : 0);
        result = 31 * result + (deleted ? 1 : 0);
        return result;
    }
}
